﻿'Tarik
Public Class frmAjoutSource

    Public Sub remplirLstViewSrc()
        lstViewSource.Items.Clear()
        For Each src In Partager.moi.lstSource
            lstViewSource.Items.Add(New ListViewItem(New String() {src.id, src.nom}))
        Next

    End Sub

    Private Sub frmAjoutSource_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        frmProces.Enabled = True
    End Sub

    Private Sub frmAjoutSource_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtSrc.Select()
        Partager.moi.remplirlstSource()
        remplirLstViewSrc()
    End Sub

    Private Sub btn_ajout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ajout.Click
        If Not String.IsNullOrEmpty(txtSrc.Text) Then
            Partager.moi.ajouterSource(txtSrc.Text)
            remplirLstViewSrc()
            txtSrc.Text = ""
            Partager.remplircmbSource(frmProces.cmbSource)
        End If
    End Sub

    Private Sub btn_supp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_supp.Click
        If lstViewSource.SelectedIndices.Count > 0 Then
            Partager.moi.supprimerSource(CInt(lstViewSource.SelectedItems(0).SubItems(0).Text))
            remplirLstViewSrc()
            Partager.remplircmbSource(frmProces.cmbSource)
        End If
    End Sub

    Private Sub txtSrc_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSrc.TextChanged
        Try
            lstViewSource.Items.Clear()

            For Each item In Partager.moi.lstSource
                If item.nom.Contains(txtSrc.Text) Then
                    lstViewSource.Items.Add(New ListViewItem(New String() {item.id, item.nom}))
                End If
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        If txtSrc.Text = "" Then
            remplirLstViewSrc()
        End If
    End Sub

    Private Sub lstViewSource_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstViewSource.DoubleClick
        For Each item As DictionaryEntry In frmProces.cmbSource.Items
            If item.Key = CInt(lstViewSource.SelectedItems(0).SubItems(0).Text) Then
                frmProces.cmbSource.SelectedItem = item
                Me.Close()
                Exit For
            End If
        Next
    End Sub
End Class